<template>
  <div class="login-container">
    <div class="login-card">
      <div class="login-title">学生信息修改</div>
      <el-form
        status-icon
        :model="reviseForm"
        :rules="rules"
        ref="ruleForm"
        class="revise-form"
      >
        账号
        <el-form-item prop="stuNumber" >
          <el-input
            readonly="readonly"
            v-model="reviseForm.stuNumber"
            prefix-icon="el-icon-user-solid"
            placeholder="账号"
            @keyup.enter.native="revise"
          />
        </el-form-item>
        姓名
        <el-form-item prop="stuName">
          <el-input
            v-model="reviseForm.stuName"
            prefix-icon="el-icon-user-solid"
            placeholder="姓名"
            @keyup.enter.native="revise"
          />
        </el-form-item>
      </el-form>
      <el-button type="primary" @click="revise">修改</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: "StudentRevise",
  created() {
    this.initStudent(this.$route.params.id);
  },
  data: function() {
    return {
      student:"",
      reviseForm: {
        stuNumber: "",
        stuName: ""
      },
      rules: {

        stuName: [{ required: true, message: "姓名不能为空", trigger: "blur" }]
      }
    };
  },
  methods: {
    revise() {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          const that = this;

          let param = new URLSearchParams();
          param.append("stuId", this.$route.params.id);
          param.append("stuName", that.reviseForm.stuName);
          that.axios.post("/api/submit_stu_info", param).then(({ data }) => {
            if (data.flag) {
              that.$message.success("修改成功");
              that.$router.push({ path: "/" });
            } else {
              that.$message.error(data.message);
            }
          });


        } else {
          return false;
        }
      });
    },
    initStudent(id){
      const that = this;
      that.axios.get("/api/stu_revise_jump/"+id).then(({ data }) => {
        this.student = data.data;
        this.reviseForm.stuName = this.student.stuName;
        this.reviseForm.stuNumber = this.student.stuNumber;
      });
    }
  }
}
</script>

<style scoped>

</style>
